<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\City;
use App\Models\Gym;
use App\Models\PickupSite;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ApiController extends Controller
{
    public function cities(Request $request)
    {
        $q = $request->get('q');

        return City::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }

    public function sites(Request $request)
    {
        $q = $request->get('q');

        return PickupSite::where([['city_id', '=', "$q"], ['is_delete', '=', 0]])->get(['id', DB::raw('name as text')]);
    }

    public function gyms(Request $request)
    {
        $q = $request->get('q');
        return Gym::where([['name', 'like', "%$q%"], ['is_delete', '=', 0], ['status', '=', 1]])->paginate(null, ['id', 'name as text']);
    }
}